package com.auxide.cah;


import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

import com.auxide.util.Logger;
import com.auxide.util.NetworkManager;
import com.auxide.util.Preferences;

public class MainActivity extends Activity implements OnClickListener {
	
	Button hostButton;
	Button joinButton;
	Button tempButton;
	NetworkManager mConnection;
    Context mContext = this;
    
    static AlertDialog mConnectDialog;
    
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		Preferences.setUpPrefs(this);
		
		hostButton = (Button) findViewById(R.id.hostButton);
		joinButton = (Button) findViewById(R.id.joinButton);
		tempButton = (Button) findViewById(R.id.game);

		hostButton.setOnClickListener(this);
		joinButton.setOnClickListener(this);
		tempButton.setOnClickListener(this);

		Logger.setContext(this);
		
		mConnection = NetworkManager.getInstance();
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

	@Override
	public void onClick(View v) {
		Intent intent = new Intent(this, HostGame.class);
		switch(v.getId()){
		case R.id.hostButton:
			intent.putExtra("Host", true);
			startActivity(intent);
			break;
		case R.id.joinButton:
			intent.putExtra("Host", false);
			startActivity(intent);
			break;
		case R.id.game:
			startActivity(intent);
			break;
		}

	}

	public static Handler handler = new Handler() {
		@Override
		public void handleMessage(Message msg) { 
			super.handleMessage(msg);

			String text = (String)msg.obj;
			if(text != null){
				Logger.popUp(text);
				return;
			}
		}
	};
}
